package leetcode.editor.cn;

import java.util.*;

public class Test {

    public List<Integer> res = new ArrayList<>();

    public void dfs(TreeNode root) {

        if (root == null) return;
        if (root.left != null) dfs(root.left);
        res.add(root.val);
        if (root.right != null) dfs(root.right);
    }

    public static int getDigitSum(int m) {
        int sum = 0;
        int i = 100;
        while (m > 0) {
            sum += m % 10;
            m = m / 10;
        }
        return sum;
    }

    public static List<Integer[]> findIndexesGreaterThanValue(int[] array, int target) {
        List<Integer[]> indexes = new ArrayList<>();
        int start = -1;
        int sumTemp = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] > target) {
                if (start == -1) {
                    start = i;
                    sumTemp += array[i];
                }
            } else {
                if (start != -1) {

                    indexes.add(new Integer[]{start, i - 1});
                    start = -1;
                }
            }
        }

        if (start != -1) {
            indexes.add(new Integer[]{start, array.length - 1});
        }

        return indexes;
    }

    public static void main(String[] args) {

        int a = 'a';
        System.out.println(a);
        char cc = 'a' -32;
        System.out.println(cc);

//        int a = Integer.parseInt("1");
//        System.out.println(a);

        int[] array = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
        int target = 5;

        List<Integer[]> indexes = findIndexesGreaterThanValue(array, target);

        System.out.println("Indexes greater than " + target + ": " + indexes);

        int[][] visited = new int[2][3];
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.println(visited[i][j]);
            }
        }

        String s = "        abaccdeff ";
        s.trim();
        System.out.println(s);
        Map<Character, Boolean> charMap = new HashMap<>();
        for (char c : s.toCharArray()) {
            charMap.put(c, charMap.containsValue(c));
        }

        int[] nums1 = {1, 2, 3};
        int[] nums2 = {2, 32, 3};
        nums1 = nums2;
        System.out.println(Arrays.toString(nums1));

        int[][] board = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
        System.out.println(board[0]);

        TreeNode root = new TreeNode(4);
        root.left = new TreeNode(2);
        root.left.left = new TreeNode(1);
        root.left.right = new TreeNode(3);
        root.right = new TreeNode(5);

        new Test().dfs(root);

        int digitSum = getDigitSum(853);

        System.out.println();

    }
}
